package im.vinci.server.music.persistence;

import im.vinci.server.music.domain.MusicalPreference;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by mingjie on 17/3/11.
 */
@Repository
public interface MusicalPreferenceMapper {

    @Insert({"<script>",
            "INSERT INTO user_music_preference ",
            "(user_id, music_style, artists) VALUES ",
            "<foreach item='item' index='index' collection='list' separator=','>",
            "(#{item.userId},#{item.musicStyle}, #{item.artists})",
            "</foreach>",
            "</script>"
    })
    int insert(@Param("list") List<MusicalPreference> list);

    @Select("SELECT user_id,music_style, artists FROM user_music_preference WHERE user_id=#{user_id} and is_deleted=0")
    List<MusicalPreference> select(@Param("user_id") long userId);

    @Update("UPDATE user_music_preference SET is_deleted=1 WHERE user_id=#{user_id}")
    int delete(@Param("user_id") long userId);
}
